package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 王加鑫
 * @Date 2021/08/18 22:53
 * @Since JDK 1.8
 */
@RestController
@RequestMapping("stu")
public class StudentController {

    @Reference
    private StudentService studentService;

    @RequestMapping("findAll")
    public PageInfo findAll(@RequestParam("currentPage") int page,@RequestParam("pageSize") int pageSize){
        return studentService.findAll(page,pageSize);
    }


    @RequestMapping("add")
    public void add(@RequestBody Student student){
        studentService.save(student);
    }

    @RequestMapping("update")
    public void updateStu(@RequestBody Student student){
        System.out.println("update .....");
        studentService.update(student);
    }

    @RequestMapping("delete")
    public void delete(@RequestBody String number){
        String substring = number.substring(0,number.length() - 1);
        System.out.println("substring = " + substring);
        studentService.delete(substring);
    }
}
